﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using GRMS;
using GRMS.App_Code;
using System.Collections;
using System.Text.RegularExpressions;

namespace GRMSTests
{
    [TestClass]
    public class UnitTest1
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region ManagementSystem Test Cases
        [TestMethod]
        public void GSMS_ProcessString_Test()
        {
            GSMS current = new GSMS();

            //Assert Assignment
            Assert.AreEqual(CommonCommands.ProcessString(@"AssignString = 'newString'", current.current), "");
            Assert.AreEqual(CommonCommands.ProcessString("Get: {AssignString}", current.current), "newString");
            Assert.AreEqual(CommonCommands.ProcessString(@"AssignInt = 10", current.current), "");
            Assert.AreEqual(CommonCommands.ProcessString("Get: {AssignInt}", current.current), "10");

            //Assert Comparison
            Assert.AreEqual(CommonCommands.ProcessString(@"str1 == str1", current.current), "true");
            Assert.AreEqual(CommonCommands.ProcessString(@"str1 == str2", current.current), "false");
            Assert.AreEqual(CommonCommands.ProcessString(@"str1 != str2", current.current), "true");

            Assert.AreEqual(CommonCommands.ProcessString(@"10 == 10", current.current), "true");
            Assert.AreEqual(CommonCommands.ProcessString(@"10 == 12", current.current), "false");
            Assert.AreEqual(CommonCommands.ProcessString(@"10 != 12", current.current), "true");
            Assert.AreEqual(CommonCommands.ProcessString(@"10 > 8", current.current), "true");
            Assert.AreEqual(CommonCommands.ProcessString(@"10 > 12", current.current), "false");
            Assert.AreEqual(CommonCommands.ProcessString(@"10 < 8", current.current), "false");
            Assert.AreEqual(CommonCommands.ProcessString(@"10 < 12", current.current), "true");

            CommonCommands.ProcessString(@"LeftSide = 20", current.current);
            CommonCommands.ProcessString(@"RightSide = 20", current.current);
            Assert.AreEqual(CommonCommands.ProcessString(@"LeftSide == RightSide", current.current), "true");

            //Assert Option
            Assert.AreEqual(CommonCommands.ProcessString(@"{true}: ifState | true {trueResult} | false {falseResult}", current.current), "trueResult");
            Assert.AreEqual(CommonCommands.ProcessString(@"{false}: ifState | true {trueResult} | false {falseResult}", current.current), "falseResult");
            Assert.AreEqual(CommonCommands.ProcessString(@"{1}: 1through4 | 1 {firstResult} | 2 {secondResult} | 3 {thirdResult} | 4 {fourthResult}", current.current), "firstResult");
            Assert.AreEqual(CommonCommands.ProcessString(@"{2}: 1through4 | 1 {firstResult} | 2 {secondResult} | 3 {thirdResult} | 4 {fourthResult}", current.current), "secondResult");
            Assert.AreEqual(CommonCommands.ProcessString(@"{3}: 1through4 | 1 {firstResult} | 2 {secondResult} | 3 {thirdResult} | 4 {fourthResult}", current.current), "thirdResult");
            Assert.AreEqual(CommonCommands.ProcessString(@"{4}: 1through4 | 1 {firstResult} | 2 {secondResult} | 3 {thirdResult} | 4 {fourthResult}", current.current), "fourthResult");

            //Assert Roll
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: d20", current.current)), 1, 20));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: _7", current.current)), 1, 20));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: 2d20", current.current)), 2, 40));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: 2_7", current.current)), 2, 40));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: d20 + 5", current.current)), 6, 25));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: _7 + 5", current.current)), 6, 25));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: d10 + d10", current.current)), 2, 20));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: _5 + d10", current.current)), 2, 20));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: d10 + d4", current.current)), 2, 14));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: _5 + _2", current.current)), 2, 14));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: d10 + d4 + 5", current.current)), 7, 19));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: _5 + _2 + 5", current.current)), 7, 19));

            CommonCommands.ProcessString(@"DieStep1 = 7", current.current);
            CommonCommands.ProcessString(@"Count1 = 2", current.current);
            CommonCommands.ProcessString(@"DieStep2 = 5", current.current);
            CommonCommands.ProcessString(@"DieStep3 = 2", current.current);
            CommonCommands.ProcessString(@"Mod1 = 5", current.current);
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: dDieStep1", current.current)), 1, 20));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: _DieStep1", current.current)), 1, 20));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: Count1dDieStep1", current.current)), 2, 40));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: Count1_DieStep1", current.current)), 2, 40));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: dDieStep1 + Mod1", current.current)), 6, 25));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: _DieStep1 + Mod1", current.current)), 6, 25));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: dDieStep2 + dDieStep2", current.current)), 2, 20));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: _DieStep2 + dDieStep2", current.current)), 2, 20));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: dDieStep2 + dDieStep3", current.current)), 2, 14));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: _DieStep2 + _DieStep3", current.current)), 2, 14));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: dDieStep2 + dDieStep3 + Mod1", current.current)), 7, 19));
            Assert.IsTrue(roll_Test(Int32.Parse(CommonCommands.ProcessString(@"Roll: _DieStep2 + _DieStep3 + Mod1", current.current)), 7, 19));

            //Assert AcceptCommand
            string complexCommand = @"
DieStep = 4;
Count = 1;
Mod = 0;
Roll: Count_DieStep + Mod;
";
            Assert.IsTrue(roll_Test(Int32.Parse(current.AcceptCommand(complexCommand)), 1, 8));
        }

        [TestMethod]
        public void GSMS_ProcessActions_Test()
        {
            GSMS current = new GSMS();
            current.current.Root = @"C:\Users\anewman\Desktop\New folder (3)\GRMS\GRMS";

            string input1 = @"Test Test";
            string input2 = @"Test Create J-Random";
            string input3 = @"Test Change Attribute; Strength 4";
            string input4 = @"Test Action; Climbing";
            string input5 = @"Test Action; Cooking";

            string result1 = current.AcceptCommand(input1);
            Assert.AreEqual("Not a valid Test Command", result1);

            string result2 = current.AcceptCommand(input2);
            Assert.AreEqual("Successfully Created J-Random Character", result2);

            string result3 = current.AcceptCommand(input3);
            Assert.AreEqual("Updated J-Random's skill of Strength to 4", result3);

            string result4 = current.AcceptCommand(input4);
            string[] resultParse = result4.Split('\r');
            Assert.AreEqual("J-Random is attempting to preform a Climbing(Athletics:Strength) check.", resultParse[0]);

            Assert.AreEqual("\nJ-Random", resultParse[1].Substring(0, 9));
            char[] Trims = { '(', ')', '/' };
            int value = Convert.ToInt32(Regex.Match(resultParse[1], @"[1-9][0-9]*").Value.Trim(Trims));
            if (value == 2)
                Assert.AreEqual("\nJ-Random failed on their roll (Roll: " + value + " Difficulity: 8) and botched it.", resultParse[1]);
            else if (value < 8)
                Assert.AreEqual("\nJ-Random failed on their roll (Roll: " + value + " Difficulity: 8).", resultParse[1]);
            else if (value > 8)
                Assert.AreEqual("\nJ-Random succeeded on their roll (Roll: " + value + " Difficulity: 8).", resultParse[1]);
            else if (value > 15)
                Assert.AreEqual("\nJ-Random succeeded on their roll (Roll: " + value + " Difficulity: 8) exceptionally well.", resultParse[1]);

            string result5 = current.AcceptCommand(input5);
            resultParse = result5.Split('\r');
            Assert.AreEqual("J-Random is attempting to preform a Cooking(Artistry:Alertness) check.", resultParse[0]);

            Assert.AreEqual("\nJ-Random", resultParse[1].Substring(0, 9));
            value = Convert.ToInt32(Regex.Match(resultParse[1], @"[1-9][0-9]*").Value.Trim(Trims));
            if (value == 2)
                Assert.AreEqual("\nJ-Random failed on their roll (Roll: " + value + " Difficulity: 8) and botched it.", resultParse[1]);
            else if (value < 8)
                Assert.AreEqual("\nJ-Random failed on their roll (Roll: " + value + " Difficulity: 8).", resultParse[1]);
            else if (value > 8)
                Assert.AreEqual("\nJ-Random succeeded on their roll (Roll: " + value + " Difficulity: 8).", resultParse[1]);
            else if (value > 15)
                Assert.AreEqual("\nJ-Random succeeded on their roll (Roll: " + value + " Difficulity: 8) exceptionally well.", resultParse[1]);
        }
        #endregion

        #region CommonCommands Test Cases
        [TestMethod]
        public void Assignment_Test()
        {
            Session session = new Session();
            string input1 = @"NewStr = 'newstring'";
            string input2 = @"NewInt = 24";

            //Can Assign Strings
            Assert.IsTrue(CommonCommands.Assignment(input1.Split('=')[0].Trim(), 
                                                    input1.Split('=')[1].Trim(), 
                                                    session));
            //Can Assign Ints
            Assert.IsTrue(CommonCommands.Assignment(input2.Split('=')[0].Trim(), 
                                                    input2.Split('=')[1].Trim(), 
                                                    session));

            input1 = @"NewStr = 'NextString'";
            input2 = @"newInt = 50";

            //Can Reassign Strings
            Assert.IsTrue(CommonCommands.Assignment(input1.Split('=')[0].Trim(), 
                                                    input1.Split('=')[1].Trim(), 
                                                    session));
            //Can Reassign Ints
            Assert.IsTrue(CommonCommands.Assignment(input2.Split('=')[0].Trim(), 
                                                    input2.Split('=')[1].Trim(), 
                                                    session));
        }
        [TestMethod]
        public void Comparison_Test()
        {
            //Can compare strings
            Assert.AreEqual(CommonCommands.Comparison("string1", "string1"), 2);
            Assert.AreEqual(CommonCommands.Comparison("string1", "string2"), -1);
            //Can compare ints
            Assert.AreEqual(CommonCommands.Comparison(5, 5), 2);
            Assert.AreEqual(CommonCommands.Comparison(5, 6), 1);
            Assert.AreNotEqual(CommonCommands.Comparison(5, 6), 2);
            //Type Sensativity
            Assert.AreEqual(CommonCommands.Comparison(5,"string1"), -1);

            Session session = new Session();

            //Can Compare strings from Session
            CommonCommands.Assignment("Str1", "'str1'", session);
            CommonCommands.Assignment("Str2", "'str1'", session);

            Assert.AreEqual(CommonCommands.Comparison(session.GetGlobal("Str1"), session.GetGlobal("Str2")), 2);
            Assert.AreEqual(CommonCommands.Comparison("str1", session.GetGlobal("Str2")), 2);
            Assert.AreEqual(CommonCommands.Comparison(session.GetGlobal("Str1"), "str1"), 2);

            CommonCommands.Assignment("Str2", "'str2'", session);

            Assert.AreEqual(CommonCommands.Comparison(session.GetGlobal("Str1"), session.GetGlobal("Str2")), -1);
            Assert.AreEqual(CommonCommands.Comparison("str1", session.GetGlobal("Str2")), -1);
            Assert.AreEqual(CommonCommands.Comparison(session.GetGlobal("Str1"), "str2"), -1);

            //Can Compare ints from Session
            CommonCommands.Assignment("Int1", 10, session);
            CommonCommands.Assignment("Int2", 10, session);

            Assert.AreEqual(CommonCommands.Comparison(session.GetGlobal("Int1"), session.GetGlobal("Int2")), 2);
            Assert.AreEqual(CommonCommands.Comparison(10, session.GetGlobal("Int2")), 2);
            Assert.AreEqual(CommonCommands.Comparison(session.GetGlobal("Int1"), 10), 2);

            CommonCommands.Assignment("Int2", 12, session);

            Assert.AreEqual(CommonCommands.Comparison(session.GetGlobal("Int1"), session.GetGlobal("Int2")), 1);
            Assert.AreEqual(CommonCommands.Comparison(10, session.GetGlobal("Int2")), 1);
            Assert.AreEqual(CommonCommands.Comparison(session.GetGlobal("Int1"), 12), 1);
        }
        [TestMethod]
        public void Option_Test()
        {
            Session session = new Session();
            string options = @"TrueFalse | true {trueResult} | false {falseResult}";
            string input1 = "true";
            string input2 = "false";

            //Verify If statements
            Assert.AreEqual(CommonCommands.Option(options, input1, session), "trueResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "falseResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input2, session), "trueResult");
            Assert.AreEqual(CommonCommands.Option(options, input2, session), "falseResult");

            options = @"TrueFalse | true {trueResult1} | false {falseResult1}";
            //Vertify saveing of old
            Assert.AreEqual(CommonCommands.Option(options, input1, session), "trueResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "falseResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input2, session), "trueResult");
            Assert.AreEqual(CommonCommands.Option(options, input2, session), "falseResult");

            options = @"1through4 | 1 {firstResult} | 2 {secondResult} | 3 {thirdResult} | 4 {fourthResult}";

            //Verify Case statements
            input1 = "1";
            Assert.AreEqual(CommonCommands.Option(options, input1, session), "firstResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "secondResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "thirdResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "fourthResult");

            input1 = "2";
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "firstResult");
            Assert.AreEqual(CommonCommands.Option(options, input1, session), "secondResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "thirdResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "fourthResult");

            input1 = "3";
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "firstResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "secondResult");
            Assert.AreEqual(CommonCommands.Option(options, input1, session), "thirdResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "fourthResult");

            input1 = "4";
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "firstResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "secondResult");
            Assert.AreNotEqual(CommonCommands.Option(options, input1, session), "thirdResult");
            Assert.AreEqual(CommonCommands.Option(options, input1, session), "fourthResult");
        }
        [TestMethod]
        public void Roll_Test()
        {
            //Verifying d2
            int Result = CommonCommands.Roll(1, 1, 0);
            Assert.IsTrue(roll_Test(Result, 1, 2));
            Result = CommonCommands.Roll(1, 1, 5);
            Assert.IsTrue(roll_Test(Result, 6, 7));
            Result = CommonCommands.Roll(1, 2, 0);
            Assert.IsTrue(roll_Test(Result, 2, 4));

            //Verifying d4
            Result = CommonCommands.Roll(2, 1, 0);
            Assert.IsTrue(roll_Test(Result, 1, 4));
            Result = CommonCommands.Roll(2, 1, 5);
            Assert.IsTrue(roll_Test(Result, 6, 9));
            Result = CommonCommands.Roll(2, 2, 0);
            Assert.IsTrue(roll_Test(Result, 2, 8));

            //Verifying d6
            Result = CommonCommands.Roll(3, 1, 0);
            Assert.IsTrue(roll_Test(Result, 1, 6));
            Result = CommonCommands.Roll(3, 1, 5);
            Assert.IsTrue(roll_Test(Result, 6, 11));
            Result = CommonCommands.Roll(3, 2, 0);
            Assert.IsTrue(roll_Test(Result, 2, 12));

            //Verifying d8
            Result = CommonCommands.Roll(4, 1, 0);
            Assert.IsTrue(roll_Test(Result, 1, 8));
            Result = CommonCommands.Roll(4, 1, 5);
            Assert.IsTrue(roll_Test(Result, 6, 13));
            Result = CommonCommands.Roll(4, 2, 0);
            Assert.IsTrue(roll_Test(Result, 2, 16));

            //Verifying d10
            Result = CommonCommands.Roll(5, 1, 0);
            Assert.IsTrue(roll_Test(Result, 1, 10));
            Result = CommonCommands.Roll(5, 1, 5);
            Assert.IsTrue(roll_Test(Result, 6, 15));
            Result = CommonCommands.Roll(5, 2, 0);
            Assert.IsTrue(roll_Test(Result, 2, 20));

            //Verifying d12
            Result = CommonCommands.Roll(6, 1, 0);
            Assert.IsTrue(roll_Test(Result, 1, 12));
            Result = CommonCommands.Roll(6, 1, 5);
            Assert.IsTrue(roll_Test(Result, 6, 17));
            Result = CommonCommands.Roll(6, 2, 0);
            Assert.IsTrue(roll_Test(Result, 2, 24));

            //Verifying d20
            Result = CommonCommands.Roll(7, 1, 0);
            Assert.IsTrue(roll_Test(Result, 1, 20));
            Result = CommonCommands.Roll(7, 1, 5);
            Assert.IsTrue(roll_Test(Result, 6, 25));
            Result = CommonCommands.Roll(7, 2, 0);
            Assert.IsTrue(roll_Test(Result, 2, 40));
        }
        private bool roll_Test(int result, int min, int max)
        {
            if (result < min)
                return false;
            else if (result > max)
                return false;
            else
                return true;
        }
        #endregion

        #region Character Creation Test Cases
        [TestMethod]
        public void CharacterCreation_Test()
        {
            Session current = new Session();
            current.Root = @"C:\Users\anewman\Desktop\New folder (3)\GRMS\GRMS";
            Character test = new Character(current);

            //Assert Creation success
            Assert.IsInstanceOfType(test, typeof(Character));
            Assert.AreEqual("0", test.Get("Agility").Value);
            Assert.AreEqual("0 + 0", test.Get("Iniative").Value);

            //Assert single property changing
            KeyValuePair<string, string> input = new KeyValuePair<string, string>("name", "Drogo");
            test.UpdateBaseProperty(input);
            Assert.AreEqual("Drogo", test.Get("name").Value);

            //Assert multi property changing
            Dictionary<string,string> input1 = new Dictionary<string, string>();
            foreach (KeyValuePair<string, string> s in test.GetList("attributes", null))
                input1.Add(s.Key, (Convert.ToInt32(s.Value) + 3).ToString());
            test.UpdateBaseProperties(input1);
            foreach (KeyValuePair<string, string> s in test.GetList("attributes", null))
                Assert.AreEqual("d6", s.Value);
            //Assert dice values come back
            Assert.AreEqual("d6", test.Get("Agility").Value);
            Assert.AreEqual("d6 + d6", test.Get("Iniative").Value);
            //Assert compiled dice value comes back
            input = new KeyValuePair<string, string>("Strength", "7");
            test.UpdateBaseProperty(input);
            Assert.AreEqual("d12 + d2", test.Get("Strength").Value);

            //Assert single combat property getting
            Assert.AreEqual(1, test.GetActions("Attack").Count);
            Assert.IsTrue(test.GetActions("Attack").ContainsKey("Unarmed Combat"));
            //Assert single combat property value getting

            //Assert single property adding
            //Assert multi combat property getting
            Hashtable ht = new Hashtable();
            ht.Add("id", "Pistol, Light");
            ht.Add("Pistol, Light", "1");
            ht.Add("section", "weapons");
            ht.Add("attr", "Agility");
            ht.Add("skill", "Pistol Guns");
            ht.Add("combat", "true");
            ht.Add("ctype", "Ranged");
            test.AddProperty(ht);
            Assert.AreEqual(2, test.GetActions("Attack").Count);
            Assert.IsTrue(test.GetActions("Attack").ContainsKey("Pistol, Light"));
            Assert.IsTrue(test.GetActions("Attack").ContainsKey("Unarmed Combat"));
            //Assert multi combat property value getting
            Assert.AreEqual("d12 + d2 + 0", test.GetActions("Attack")["Unarmed Combat"]);
            Assert.AreEqual("d6 + 0", test.GetActions("Attack")["Pistol, Light"]);

            //Assert multi property adding
            Dictionary<string, Hashtable> attr = XMLReader.GetValuesFrom("/App_Data/AdvancedSkills.xml", "sections section", "Animals", current);
            test.AddProperties(attr);

            //Assert multi non-combat property getting
            Assert.AreEqual(6, test.GetActions("Animals", "skills").Count);
            //Assert multi non-combat property value getting
            foreach (KeyValuePair<string, string> kvp in test.GetActions("Animals", "skills"))
                if (kvp.Key == "Animals")
                    Assert.AreEqual("GM + 0", kvp.Value);
                else
                    Assert.AreEqual("d6 + 0", kvp.Value);
        }
        #endregion

        #region ActionEvent Flow Test Cases
        [TestMethod]
        public void Create_ActionEventRequest_Test()
        {
            Session current = new Session();
            current.Root = @"C:\Users\anewman\Desktop\New folder (3)\GRMS\GRMS";
            Character test = new Character(current);
            test.ID = "Bob";
            Character npc = new Character(current);
            npc.ID = "Goblin";
            current.AddCharacter(test);
            current.AddNPC(npc);
            Dictionary<string,string> input1 = new Dictionary<string, string>();
            foreach (KeyValuePair<string, string> s in test.GetList("attributes", null))
                input1.Add(s.Key, (Convert.ToInt32(s.Value) + 3).ToString());
            test.UpdateBaseProperties(input1);
            npc.UpdateBaseProperties(input1);

            Hashtable ht = new Hashtable();
            ht.Add("id", "Climbing");
            ht.Add("Climbing", "3");
            ht.Add("section", "skills");
            ht.Add("type", "Athletics");
            ht.Add("attr", "Strength");
            ht.Add("skill", "this");
            ht.Add("combat", "false");
            test.AddProperty(ht);
            
            ht = new Hashtable();
            ht.Add("id", "Dodge");
            ht.Add("Dodge", "3");
            ht.Add("section", "skills");
            ht.Add("type", "Athletics");
            ht.Add("attr", "Agility");
            ht.Add("skill", "this");
            ht.Add("combat", "both");
            ht.Add("ctype", "Defense");
            test.AddProperty(ht);

            ActionEventRequest AER = test.GetEventRequest("Climbing");
            Assert.AreEqual(AER.Actor, test.ID);
            Assert.AreEqual(AER.MainType, "Climbing");
            Assert.AreEqual(AER.SkillCheck, "d6 + d6");
            Assert.AreEqual(AER.MinSkillCheck, "2");
            Assert.AreEqual(AER.SubType, "Athletics:Strength");
            Assert.IsTrue(AER.Targets.Count == 0);

            AER = test.GetEventRequest("Unarmed Combat", npc.ID);
            Assert.AreEqual(AER.Actor, test.ID);
            Assert.AreEqual(AER.MainType, "Unarmed Combat");
            Assert.AreEqual(AER.SkillCheck, "d6 + 0");
            Assert.AreEqual(AER.MinSkillCheck, "1");
            Assert.AreEqual(AER.SubType, "Attack:Unarmed Combat:Strength");
            Assert.IsTrue(AER.Targets.Count == 1);
            Assert.IsTrue(AER.Targets.Contains(npc.ID));

            AER = test.GetEventRequest("Dodge", test.ID);
            Assert.AreEqual(AER.Actor, test.ID);
            Assert.AreEqual(AER.MainType, "Dodge");
            Assert.AreEqual(AER.SkillCheck, "d6 + d6");
            Assert.AreEqual(AER.MinSkillCheck, "2");
            Assert.AreEqual(AER.SubType, "Defense:Athletics:Agility");
            Assert.IsTrue(AER.Targets.Count == 1);
            Assert.IsTrue(AER.Targets.Contains(test.ID));
        }
        [TestMethod]
        public void Read_ActionEventLibrary_Test()
        {
            Session current = new Session();
            current.Root = @"C:\Users\anewman\Desktop\New folder (3)\GRMS\GRMS";
            string filename = "/App_Data/ActionEventLibrary.xml";
            ActionEventLibrary AEL = new ActionEventLibrary(filename, current);

            string output = AEL.GetActionEventDefination("UnopposedCheck");
            string expected = @"
      PrintLn('{Actor} is attempting to preform a {MainType}({SubType}) check.');
      resultRoll = {Roll: {SkillCheck}};
      {GM_GetDifficulity()};
      resultDef += {FailCheck};
      resultDef += {BotchCheck};
      resultDef += {SucceedCheck};
      resultDef += {HeroicCheck};
      PrintLn('{Actor}' + [Get: {resultDef}]);
    ";
            Assert.AreEqual(expected, output);

            output = AEL.GetActionEventDefination("OpposedCheck");
            expected = @"
      {TargetCode}
        PrintLn('{Actor} is attempting to preform a {MainType}({SubType}) check against {Target}.');
        resultRoll = {Roll: {SkillCheck}};
        {Target_GetDifficulity({Target})};
        resultDef += {FailCheck};
        resultDef += {BotchCheck};
        resultDef += {SucceedCheck};
        resultDef += {HeroicCheck};
        PrintLn('{Actor}' + [Get: {resultDef}]);
    ";
            Assert.AreEqual(expected, output);

            output = AEL.GetActionEventDefination("Equip");
            expected = @"
      Equip(Actor, Equipment, true);
      PrintLn('{Actor} has equipped {Equipment}');
    ";
            Assert.AreEqual(expected, output);

            output = AEL.GetActionEventDefination("Equip");
            Assert.AreEqual(expected, output);
        }
        [TestMethod]
        public void Create_ActionEvent_Test()
        {
            Session current = new Session();
            current.Root = @"C:\Users\anewman\Desktop\New folder (3)\GRMS\GRMS";
            Character test = new Character(current);
            test.ID = "Bob";
            current.AddCharacter(test);
            Dictionary<string, string> input1 = new Dictionary<string, string>();
            foreach (KeyValuePair<string, string> s in test.GetList("attributes", null))
                input1.Add(s.Key, (Convert.ToInt32(s.Value) + 3).ToString());
            test.UpdateBaseProperties(input1);

            Hashtable ht = new Hashtable();
            ht.Add("id", "Climbing");
            ht.Add("Climbing", "3");
            ht.Add("section", "skills");
            ht.Add("type", "Athletics");
            ht.Add("attr", "Strength");
            ht.Add("skill", "this");
            ht.Add("combat", "false");
            test.AddProperty(ht);

            ActionEventRequest AER = test.GetEventRequest("Climbing");

            ActionEventFactory AEF = new ActionEventFactory(current);
            ActionEvent AE = AEF.GenerateActionEvent(AER);

            Assert.AreEqual(AER, AE.Request);

            List<string> listTest = new List<string>();
            listTest.Add("PrintLn('Bob is attempting to preform a Climbing(Athletics:Strength) check.')");
            listTest.Add("resultRoll = {Roll: d6 + d6}");
            listTest.Add("resultDef += {[Get: {resultRoll}] <= 8} :  | true {' failed on their roll (Roll: ' + [Get: {resultRoll}] + ' Difficulity: 8)'} | default {''}");
            listTest.Add("resultDef += {[Get: {resultRoll}]} :  | 2 {' and botched it'} | default {''}");
            listTest.Add("resultDef += {[Get: {resultRoll}] > 8} :  | true {' succeeded on their roll (Roll: ' + [Get: {resultRoll}] + ' Difficulity: 8)'} | default {''}");
            listTest.Add("resultDef += {[Get: {resultRoll}] > 8 + 7} :  | true {' exceptionally well.'} | default {'.'}");
            listTest.Add("PrintLn('Bob' + [Get: {resultDef}])");
            Assert.AreEqual(listTest[0], AE.Script[0]);
            Assert.AreEqual(listTest[1], AE.Script[1]);
            Assert.AreEqual(listTest[2], AE.Script[2]);
            Assert.AreEqual(listTest[3], AE.Script[3]);
            Assert.AreEqual(listTest[4], AE.Script[4]);
            Assert.AreEqual(listTest[5], AE.Script[5]);
            Assert.AreEqual(listTest[6], AE.Script[6]);
        }
        [TestMethod]
        public void Process_ActionEventHandler_Test()
        {
            Session current = new Session();
            current.Root = @"C:\Users\anewman\Desktop\New folder (3)\GRMS\GRMS";
            Character test = new Character(current);
            test.ID = "Bob";
            current.AddCharacter(test);
            Dictionary<string, string> input1 = new Dictionary<string, string>();
            foreach (KeyValuePair<string, string> s in test.GetList("attributes", null))
                input1.Add(s.Key, (Convert.ToInt32(s.Value) + 3).ToString());
            test.UpdateBaseProperties(input1);

            Hashtable ht = new Hashtable();
            ht.Add("id", "Climbing");
            ht.Add("Climbing", "3");
            ht.Add("section", "skills");
            ht.Add("type", "Athletics");
            ht.Add("attr", "Strength");
            ht.Add("skill", "this");
            ht.Add("combat", "false");
            test.AddProperty(ht);

            ActionEventRequest AER = test.GetEventRequest("Climbing");

            ActionEventFactory AEF = new ActionEventFactory(current);
            ActionEvent AE = AEF.GenerateActionEvent(AER);

            ActionEventHandler AEH = new ActionEventHandler(current);

            string result = AEH.ProcessActionEvent(AE);
            
            string[] resultParse = result.Split('\r');
            Assert.AreEqual("Bob is attempting to preform a Climbing(Athletics:Strength) check.", resultParse[0]);
            
            Assert.AreEqual("\nBob", resultParse[1].Substring(0, 4));
            char[] Trims = { '(', ')', '/' };
            int value = Convert.ToInt32(Regex.Match(resultParse[1], @"[1-9][0-9]*").Value.Trim(Trims));
            if (value == 2)
                Assert.AreEqual("\nBob failed on their roll (Roll: " + value + " Difficulity: 8) and botched it.", resultParse[1]);
            else if (value < 8)
                Assert.AreEqual("\nBob failed on their roll (Roll: " + value + " Difficulity: 8).", resultParse[1]);
            else if (value > 8)
                Assert.AreEqual("\nBob succeeded on their roll (Roll: " + value + " Difficulity: 8).", resultParse[1]);
            else if (value > 15)
                Assert.AreEqual("\nBob succeeded on their roll (Roll: " + value + " Difficulity: 8) exceptionally well.", resultParse[1]);
        }
        #endregion

        #region XMLReader Test Cases
        [TestMethod]
        public void GetValueFrom_Test()
        {
            Session current = new Session();
            current.Root = @"C:\Users\anewman\Desktop\New folder (3)\GRMS\GRMS";

            string filename = "/App_Data/CharacterSheet.xml";
            string s = "sheet system skillcheck";
            Hashtable result = XMLReader.GetValueFrom(filename, s, current);

            Assert.IsNotNull(result);
            Assert.IsTrue("Result : FormatDie | 0 {'0'} | 1 {'d2'} | 2 {'d4'} | 3 {'d6'} | 4 {'d8'} | 5 {'d10'} | 6 {'d12'} | default {'d12 + (Result - 6)'})".Equals(result["value"]));
        }
        [TestMethod]
        public void GetValuesFrom_Test()
        {
            Session current = new Session();
            current.Root = @"C:\Users\anewman\Desktop\New folder (3)\GRMS\GRMS";

            string filename = "/App_Data/CharacterSheet.xml";
            string s = "sheet section";
            Dictionary<string, Hashtable> result = XMLReader.GetValuesFrom(filename, s, current);
            Hashtable brief = result["brief"];
            Hashtable attributes = result["attributes"];
            Hashtable derived = result["derived_attributes"];
            Hashtable shock_points = result["shock_points"];
            Hashtable skills = result["skills"];
            Hashtable assets = result["assets"];
            Hashtable complications = result["complications"];
            Hashtable weapons = result["weapons"];
            Hashtable armor = result["armor"];
            Hashtable gear = result["gear"];
            Hashtable history = result["history"];

            Assert.AreEqual(4, brief.Keys.Count);
            Assert.AreEqual(6, attributes.Keys.Count);
            Assert.AreEqual(4, derived.Keys.Count);
            Assert.AreEqual(2, shock_points.Keys.Count);
            Assert.AreEqual(22, skills.Keys.Count);
            Assert.AreEqual(0, assets.Keys.Count);
            Assert.AreEqual(0, complications.Keys.Count);
            Assert.AreEqual(0, weapons.Keys.Count);
            Assert.AreEqual(0, armor.Keys.Count);
            Assert.AreEqual(0, gear.Keys.Count);
            Assert.AreEqual(0, history.Keys.Count);
        }
        #endregion
    }
}
